package cn.zane.designPattern.behaviorPatterns.chainOfResponsibilityPatterns.oldCode;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zane
 * @date 2025/01/22
 * @Description
 */
@Slf4j
public class AuthController {

    private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public AuthInfo doAuth(String userId, String orderId, Date authDate) throws ParseException {

        // 三级审批
        Date date = AuthService.queryAuthInfo("10001", orderId);
        if (null == date) return new AuthInfo("001", "单号: ", orderId, " 状态：待三级审批负责人 ", "组长");

        // 二级审批
        if (authDate.after(format.parse("2025-01-22 00:00:00")) && authDate.before(format.parse("2025-01-30 00:00:00"))) {
            date = AuthService.queryAuthInfo("10002", orderId);
            if (null == date) return new AuthInfo("001", "单号: ", orderId, " 状态：待二级审批负责人 ", "经理");
        }

        // 一级审批
        if (authDate.after(format.parse("2025-01-25 00:00:00")) && authDate.before(format.parse("2025-01-26 00:00:00"))) {
            date = AuthService.queryAuthInfo("10003", orderId);
            if (null == date) return new AuthInfo("001", "单号: ", orderId, " 状态：待二级审批负责人 ", "老总");
        }

        return new AuthInfo("0001", "单号：", orderId, " 状态：审批完成");
    }


    public static void main(String[] args) throws ParseException {
        AuthController authController = new AuthController();

        // 模拟三级负责人审批
        log.info("测试结果：{}", JSON.toJSONString(authController.doAuth("zane", "1000998004813441", new Date())));
        log.info("测试结果：{}", "模拟三级负责人审批，组长");
        AuthService.auth("1000013", "1000998004813441");

        // 模拟二级负责人审批                                 
        log.info("测试结果：{}", JSON.toJSONString(authController.doAuth("zane", "1000998004813441", new Date())));
        log.info("测试结果：{}", "模拟二级负责人审批，经理");
        AuthService.auth("1000012", "1000998004813441");

        // 模拟一级负责人审批
        log.info("测试结果：{}", JSON.toJSONString(authController.doAuth("zane", "1000998004813441", new Date())));
        log.info("测试结果：{}", "模拟一级负责人审批，老总");
        AuthService.auth("1000011", "1000998004813441");

        log.info("测试结果：{}", "审批完成");
    }
}
